package com.hydra.baseui.recyclerlist;

import android.content.Context;
import androidx.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

public class ViewClassItemHolderBuilder implements ItemHolderBuilder {
	
	private Class<? extends View>[] mViewClzs;

	public ViewClassItemHolderBuilder(Class<? extends View>[] clzs) {
		mViewClzs = clzs;
	}
	
	@Override
	@Nullable
	public BaseItemHolder buildItem(ViewGroup parent, int type) {
		 try {
			return new BaseItemHolder(mViewClzs[type].getConstructor(Context.class)
					.newInstance(parent.getContext()));
		} catch (Exception e) {
			Log.e(getClass().getSimpleName(), "build Item failed : " + e.toString());
			return null;
		}
	}
	
	@Override
	public void release() {
		mViewClzs = null;
	}
}
